package com.yanqu.road.dao.impl.activity.springunionbanquet;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.springunionbanquet.config.SpringUnionBanquetAwardInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SpringUnionBanquetConfigDaoImpl extends TempDao {

    private static String getSpringUnionBanquetAwardInfoSql = "select * from `t_s_activity_tusu_award` where `activityId`=? ORDER BY `dishId` ASC";
    public List<SpringUnionBanquetAwardInfo> getSpringUnionBanquetAwardInfoList(int activityId) {
        List<SpringUnionBanquetAwardInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSpringUnionBanquetAwardInfoSql);
            int i = 1;
            call.setInt(i, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SpringUnionBanquetAwardInfo data = new SpringUnionBanquetAwardInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setDishId(rs.getInt("dishId"));
                data.setName(rs.getString("name"));
                data.setResource(rs.getString("resource"));
                data.setResourceList(StringUtils.stringToIntegerList(data.getResource(), "\\|"));

                data.setSpecialAward(rs.getString("specialAward"));
                data.setSpecialAwardList(StringUtils.stringToStringList(data.getSpecialAward(), "\\|"));

                data.setOrdinaryAverage(rs.getString("ordinaryAverage"));

                data.setOrdinaryLeast(rs.getInt("ordinaryLeast"));
                list.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}
